/**
 * 
 */
package com.dingding.order.core.myorder.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.AbstractResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.order.core.myorder.biz.IGetMyOrderService;
import com.dingding.order.core.myorder.dao.IGetMyOrderDao;
import com.dingding.order.dto.myorder.MyOrder;
import com.dingding.order.dto.myorder.ReqMyOrderDTO;
import com.dingding.order.dto.myorder.ResMyOrderDTO;
import com.dingding.order.dto.myorder.SpeCusOrdInfoResult;
import com.dingding.order.dto.myorder.UserTakeInformation;

/**
 * @ClassName: GetMyOrderServiceImpl
 * @Description:获得我的订单服务实现
 * @author zhouxuan
 * @date 2016年7月5日 上午10:06:28
 * @since V2.3.0
 */
@Component("getMyOrderService")
public class GetMyOrderServiceImpl extends AbstractResponse<ResMyOrderDTO, ReqMyOrderDTO>
		implements IGetMyOrderService {

	@Resource(name = "getMyOrderDao")
	IGetMyOrderDao getMyOrderDao;

	/**
	 * @Title: getMyOrder
	 * @Description:获得我的订单
	 * @author zhouxuan
	 * @since V2.3.0
	 */
	public String getMyOrder(String requestData) {

		// 封装响应bean
		ResponseEntity<ResMyOrderDTO> response = new ResponseEntity<ResMyOrderDTO>();

		// 将请求转换成bean
		ReqMyOrderDTO reqMyOrderDTO = super.parseRequestJson(requestData);
		// 1.验证参数
		if (!validateParam(response, reqMyOrderDTO)) {
			return super.responseBeanToJson(response);
		}
		// 2.获得我的订单
		List<MyOrder> orderLists = getMyOrderDao.getMyOrderList(reqMyOrderDTO);
		// 3.获得用户总搭乘和总接乘次数
		UserTakeInformation userTakeInformation = getMyOrderDao.getUserTakeImformation(reqMyOrderDTO.getUserId());
		// 4.封装响应
		assemblyContent(response, orderLists, userTakeInformation);

		return super.responseBeanToJson(response);

	}

	/**
	 * @Title: assemblyContent
	 * @Description:封装响应
	 * @author zhouxuan
	 * @since V2.3.0
	 */
	private void assemblyContent(ResponseEntity<ResMyOrderDTO> response, List<MyOrder> orderLists,
			UserTakeInformation userTakeInformation) {

		ResMyOrderDTO resMyOrderDTO = new ResMyOrderDTO();
		// 将订单列表存入响应bean
		resMyOrderDTO.setOrderList(orderLists);
		// 将接乘数存入响应bean
		resMyOrderDTO.setPickUpMeters(userTakeInformation.getPickUpMeters());
		// 将搭乘数存入响应bean
		resMyOrderDTO.setRideMeters(userTakeInformation.getRideMeters());

		response.setResponseBody(resMyOrderDTO);
		response.setCode(HttpStatus.SC_OK);

	}

	/**
	 * @Description:获取乘客的专车订单信息
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public List<SpeCusOrdInfoResult> getCusSpecialOrder(String userId) {
		
		return this.getMyOrderDao.getCustomerSpecialOrder(userId);
	}
}
